package com.wjjumpad.cwjjumpad.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.wjjumpad.cwjjumpad.R;
import com.wjjumpad.cwjjumpad.model.AppInfoModel;

import java.util.List;


public class appListAdapter extends ArrayAdapter<AppInfoModel> {
    private int resourceId;
    private List<AppInfoModel> objects;
    private Context context;

    public appListAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<AppInfoModel> objects) {
        super(context, resource, objects);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Nullable
    @Override
    public AppInfoModel getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView==null){
            viewHolder = new ViewHolder();
            LayoutInflater layoutInflater = LayoutInflater.from(context);
//            convertView = layoutInflater.inflate(R.layout.activity_list_item,null);
//            viewHolder.imageView = convertView.findViewById(R.id.iv_image);
//            viewHolder.title = convertView.findViewById(R.id.tv_title);
//            viewHolder.content = convertView.findViewById(R.id.tv_content);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        AppInfoModel appinfo = objects.get(position);
        if (appinfo!=null){
//            viewHolder.imageView.setBackgroundResource(appinfo.getImg());
//            viewHolder.title.setText(appinfo.getTitle());
            viewHolder.content.setText(appinfo.getContent());
        }
        return convertView;
    }

    private static class ViewHolder{
        ImageView imageView;
        TextView title;
        TextView content;
    }



}
